package com.fang.config.event;

import com.fang.config.listener.MsgListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.Clock;
import java.util.concurrent.TimeUnit;

/**
 * @author Fang Ruichuan
 * @date 2022-09-13 16:02
 */
@Component
@Slf4j
public class ApplicationContext {

    @Autowired
    private MsgListener msgListener;

    public void publishEvent(OrderProductEvent orderProductEvent) throws InterruptedException {
        long start = Clock.systemUTC().millis();
        TimeUnit.MILLISECONDS.sleep(3000);
        long end = Clock.systemUTC().millis();
        log.info("检验订单价格，耗时：({})毫秒", (end - start));
    }

    public void publishEvent(MsgEvent event) {
        msgListener.sendMsg(event);
    }
}
